package net.ipi.ch03;

import java.util.Timer;
import java.util.TimerTask;

import net.ipi.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

public class HandlerTest extends Activity
{
	int[] imgRes = new int[] { R.drawable.luffy, R.drawable.roger,
			R.drawable.zoro, R.drawable.sanji, R.drawable.teach };

	int index = 0;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.handler_test);
		
		final ImageView img = (ImageView)findViewById(R.id.img);
		
		
		final Handler myHandler = new Handler(){
			@Override
			public void handleMessage(Message msg)
			{
				if(msg.what == 0x1233)
				{
					img.setImageResource(imgRes[index++ % imgRes.length]);
				}
			}
		};
		
		new Timer().schedule(new TimerTask()
		{
			
			@Override
			public void run()
			{
				myHandler.sendEmptyMessage(0x1233);
				
			}
		},0,1200);
		
	}

}
